'use strict';
// 获取数据库的引用
const db = uniCloud.database()
const $ = db.command.aggregate
exports.main = async (event, context) => {
	
	const {
		user_id,
		name,
		value
	} = event
	
	const userinfo = await db.collection('users').doc(user_id).get()
	const likes_ids = userinfo.data[0].likes_ids
	
	const list = await db.collection('list')
	.aggregate()
	// 追加字段
	.addFields({
		is_like: $.in(['$_id', likes_ids])
	})
	.match({
		type: name,
		content: new RegExp(value)
	})
	.project({
		type:false
	})
	.end()
	
	// 返回数据给客户端
	return {
		code: 200,
		message: "数据请求成功",
		data: list.data
	}
};
